package com.example.demo.controller;

import com.example.demo.model.Student;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Arrays;
import java.util.List;


@RequestMapping("/request")
@RestController
public class RequerController {
    @RequestMapping("/hello")
    public String r90(){
        return "Hello SpringMvvc";
    }

    @RequestMapping("/r1")
    public String r1(String name){
        return "接到参数，name:"+name;
    }

    @RequestMapping("/r2")
    public String r2(Integer age){
       return "接收到参数 age：" +age;
    }

    @RequestMapping("/r3")
    public String r3(int age){
        return "age :" + age;
    }


    @RequestMapping("/r4")
    public String r4(Student student){
        return "接到参数：student "+student;
    }

    @RequestMapping("/r5")
    public String r5(@RequestParam(value = "name",required = false) String userName){
        return "接到参数，name ："+ userName;
    }


    @RequestMapping("/r6")
    public String r6(String[] array){
        return "接到参数，array："+ Arrays.toString(array);
    }

    @RequestMapping("/r88")
    public String r88(String[]  array){
        return "接到参数，array:"+Arrays.toString(array);
    }

    @RequestMapping("/r7")
    public String r7(@RequestParam(value = "list",required = false) List<String> list){
        return "接到参数：list"+list;
    }


    @RequestMapping("/r8")
    public Student r8(@RequestBody Student student){
        return student;
    }

   @RequestMapping("/r10")
   public String r10(@RequestPart("file") MultipartFile imgFile){
        String originalFilename  = imgFile.getOriginalFilename();
        return "接收到文件，文件名称是:"+originalFilename;
   }


    //从路径中获取URL的参数：
    @RequestMapping("/article/{articleId}")
    public String r11(@PathVariable("articleId") Integer articleId){
        return "接到参数：artilceId:"+ articleId;
    }

    @ResponseBody
    @RequestMapping(value = "/setContentType",produces =  "application/json")
    public String setContentType(){
        return "{\"OK\":1}";
    }



}
